package com.homework.service;

import com.homework.dao.EditorDao;
import com.homework.util.TxtToMyHomework;

public class EditorService {
	private static EditorService softwareService = null;
	private EditorDao editorDao;
	
	public EditorService() {
		this.editorDao = EditorDao.getInstance();
	}
	
	public static EditorService getInstance() {
		if(softwareService == null) {
			softwareService = new EditorService();
		}
		return softwareService;
	}
	
	public boolean saveHomeworkT(String json,String homeworkIdT,Object stuId)
	{
		int a[] = editorDao.getBatchChoose(homeworkIdT);
		int chooseId = editorDao.getChooseStu(a[1],stuId);
		return editorDao.saveHomeworkT(json,a[0],chooseId);
	}
	
	public boolean updateHomework(String json,String homeworkIdT)
	{
		editorDao.updateHomeworkState(homeworkIdT);
		return editorDao.updateHomework(json,homeworkIdT);
	}
	
	public String getHomework(String homeworkId)
	{
		int status = editorDao.getStatus(homeworkId);
		String homework = editorDao.getHomework(homeworkId);
		if(status == 6){
			homework = TxtToMyHomework.txtToMyHomework(homework);
		}
		System.out.println(homework);
		return homework;
	}
}
